package com.miyake.dsp.generator;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;

public class PulseGenerator implements Processor {
	private PulseSetting setting;
	
	public PulseGenerator(PulseSetting setting) {
		super();
		this.setting = setting;
	}

	@Override
	public void setSource(ComplexArray source) {

	}

	@Override
	public ComplexArray getProcessed() {

		
		int len = (int)(setting.getWidth() * setting.getFrequency());
		int margin = (int)(len * setting.getMargin() / 100);
		double[] pulse = new double[len + margin * 2];
		for (int i = 0; i < pulse.length; i++) {
			if (i >= margin && i <= len + margin) {
				pulse[i] = setting.getMagnitude();
			}
			else {
				pulse[i] = 0;
			}
		}
		return new ComplexArray(pulse, null);
	}

	public PulseSetting getSetting() {
		return setting;
	}

	public void setSetting(PulseSetting setting) {
		this.setting = setting;
	}

	@Override
	public ComplexArray getSource() {
		return null;
	}

}
